﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LiteFetion;
using LiteFetion.Model;
using LiteFetion.Notify;

namespace TestLiteFetion
{
    class Program
    {
        static void Main(string[] args)
        {
            Event.BuddyConfirmedNotify += new EventHandler<EventArgs>(Notify_BuddyConfirmedNotify);
            Event.BuddyInviteNotify += new EventHandler<EventArgs>(Notify_BuddyInviteNotify);
            Event.BuddyMessageNotify += new EventHandler<EventArgs>(Notify_BuddyMessageNotify);
            Event.BuddyStateNotify += new EventHandler<EventArgs>(Notify_BuddyStateNotify);
            Event.ClientStateNotify += new EventHandler<EventArgs>(Notify_ClientStateNotify);

            FetionClient client = new FetionClient();
            VerifyImage img = client.GetVerifyImage(VerifyImage.TYPE_LOGIN);
            Console.WriteLine(img.SessionId == null ? "" : img.SessionId);

            img.VerifyCode = Console.ReadLine();

            Console.WriteLine(client.Login("15875607893", "qq4347893", BuddyState.ONLINE, img));

            Console.ReadLine();

            List<Buddy> list = null;
            List<Cord> clist = null;

            //默认分组
            Console.WriteLine("-------------[ 默认分组 ]------------------");
            list = client.BuddyManager.GetBuddyListWithoutCord();
            foreach (Buddy b in list)
            {
                Console.WriteLine(b);
            }

            //其他分组
            clist = client.CordList;
            foreach (Cord c in clist)
            {
                Console.WriteLine("----------[" + c.Id + "::" + c.Name + "]------------");
                list = client.BuddyManager.GetBuddyListByCord(c);
                foreach (Buddy b in list)
                {
                    Console.WriteLine(b);
                }
            }

            //陌生人
            Console.WriteLine("-------------[ 陌生人 ]------------------");
            list = client.BuddyManager.GetStrangerList();
            foreach (Buddy b in list)
            {
                Console.WriteLine(b);
            }

            //黑名单
            Console.WriteLine("-------------[ 黑名单 ]------------------");
            list = client.BuddyManager.GetBlackList();
            foreach (Buddy b in list)
            {
                Console.WriteLine(b);
            }

            Console.WriteLine(client.MessageManager.SendSelfSM("来自LiteFetion的短信"));

            //设置心情短语
            //Console.WriteLine("SetImpresa:" + client.UserManager.SetImpresa("ABDEE"));

            //设置在线状态
            Console.WriteLine("SetPresence:" + client.UserManager.SetPresence(BuddyState.AWAY, "我吃饭去了~~~"));

            DateTime dt = DateTime.Now.AddMinutes(11);

            List<Buddy> a = new List<Buddy>();
            a.Add(client.User);
            Console.WriteLine(client.MessageManager.SendScheduleSMS(a, "测试定时", 11));
            Console.ReadLine();

            client.Logout();
        }

        public static void Notify_BuddyConfirmedNotify(object sender, EventArgs e)
        {
            BuddyConfirmedNotify notify = sender as BuddyConfirmedNotify;

            Console.WriteLine(notify.ToString());
        }
        public static void Notify_BuddyInviteNotify(object sender, EventArgs e)
        {
            BuddyInviteNotify notify = sender as BuddyInviteNotify;
            notify.FetionClient.BuddyManager.BuddyAgreeInvite(notify.Buddy, true, null, null);
            Console.WriteLine(notify.ToString());
        }
        public static void Notify_BuddyMessageNotify(object sender, EventArgs e)
        {
            BuddyMessageNotify notify = sender as BuddyMessageNotify;

            Console.WriteLine(notify.ToString());
        }
        public static void Notify_BuddyStateNotify(object sender, EventArgs e)
        {
            BuddyStateNotify notify = sender as BuddyStateNotify;

            Console.WriteLine(notify.ToString());
        }
        public static void Notify_ClientStateNotify(object sender, EventArgs e)
        {
            ClientStateNotify notify = sender as ClientStateNotify;

            Console.WriteLine(notify.ToString());
        }
    }
}
